//
//  LightingControl.m
//  iPhoneControlApplication
//
//  Created by Elliot Chapple on 11/04/2009.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "ThermostatControl.h"


@implementation ThermostatControl

//synthesize all aspects from the header file
@synthesize hotWaterSwitch;
@synthesize heatingSwitch;
@synthesize heatingTemperatureLabel;
@synthesize heatingTempUp;
@synthesize heatingTempDown;
@synthesize boilerOverride;
@synthesize boilerOverrideView;
@synthesize heatingTempSlider;


//Methods
-(IBAction)boilerOverrideSwitchChanged:(id)sender
{
	//Link to Segmented Control in Interface Builder
	UISegmentedControl *segmentedControl = (UISegmentedControl *)sender;
	NSInteger segment = segmentedControl.selectedSegmentIndex;
	
	//Create if statement to see if controls are visible or not using the kShowMasterControls
	//variable defined within the header file
	if (segment == kShowBoilderOverride) [boilerOverrideView setHidden:NO];
	else [boilerOverrideView setHidden:YES];
}


-(IBAction)toggleBoilerOverride:(id)sender
{
	UISwitch *masterSwitch = (UISwitch *)sender;
	BOOL setting = masterSwitch.isOn;
	[hotWaterSwitch	setOn:setting animated:YES];
	[heatingSwitch	setOn:setting animated:YES];
}


-(IBAction)tempUpButtonPressed
{
	
	NSString *currentValue = heatingTemperatureLabel.text;
	int newValue = [currentValue intValue];
	newValue = newValue + 1;
	NSString *updatedvalue = [[NSString alloc] initWithFormat:@"%d", newValue];
	heatingTemperatureLabel.text = updatedvalue;
	[updatedvalue release];
	
}


-(IBAction)tempDownButtonPressed
{
	NSString *currentValue1 = heatingTemperatureLabel.text;
	int newValue1 = [currentValue1 intValue];
	newValue1 = newValue1 - 1;
	NSString *updatedvalue1 = [[NSString alloc] initWithFormat:@"%d", newValue1];
	heatingTemperatureLabel.text = updatedvalue1;
	[updatedvalue1 release];
}

-(IBAction)sliderChanged:(id)sender
{
	UISlider *slider = (UISlider *)sender;
	int tempChange = (int)(slider.value);
	NSString *newTemp = [[NSString alloc] initWithFormat:@"%d", tempChange];
	heatingTemperatureLabel.text = newTemp;
	[newTemp release];
}

/* Standard Code from Apple Inc - Defaults left to preserve integrity
 
 
 // The designated initializer. Override to perform setup that is required before the view is loaded.
 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
 if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
 // Custom initialization
 }
 return self;
 }
 */

/*
 // Implement loadView to create a view hierarchy programmatically, without using a nib.
 - (void)loadView {
 }
 */

/*
 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
 - (void)viewDidLoad {
 [super viewDidLoad];
 }
 */

/*
 // Override to allow orientations other than the default portrait orientation.
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 // Return YES for supported orientations
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
 }
 */

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}

//Memory Management
- (void)dealloc {
    [super dealloc];
}


@end




